Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setup gha 107 #7

Merged
merged 38 commits into from
Feb 22, 2024
Merged

Setup gha 107 #7

merged 38 commits into from
Feb 22, 2024

Conversation

chelseybeck
Copy link
Member

@chelseybeck chelseybeck commented Feb 8, 2024

Changes:

  • Added a GitHub action to run a plan when a PR is opened and output the plan as a comment on the PR.
  • Added access level tags to users
  • To test the action, added a custom policy that grants iam services admins permission to update passwords and create keys for users
  • Updated policy attachments to use a mapping

Testing

These changes have been tested and produce the plan attached to the latest comment

Copy link

github-actions bot commented Feb 19, 2024

Terraform plan in .

Error: No configuration files
Error: No configuration files

Plan requires configuration to be present. Planning without a configuration
would mark everything for destruction, which is normally not what is desired.
If you would like to destroy everything, run plan with the -destroy option.
Otherwise, create a Terraform configuration file (.tf file) and try again.

❌ Failed to generate plan in Write Terraform Plan to Pull Request #27

Copy link

github-actions bot commented Feb 19, 2024

Terraform plan in terraform

Plan: 5 to add, 7 to change, 2 to destroy.
Terraform used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
+   create
!~  update in-place
-   destroy

Terraform will perform the following actions:

  # module.aws_custom_policies.aws_iam_policy.custom_policy["IAMServicesAdmin"] will be created
+   resource "aws_iam_policy" "custom_policy" {
+       arn         = (known after apply)
+       description = "Policy granting IAM services admins permissions to make changes to user accounts"
+       id          = (known after apply)
+       name        = "IAMServicesAdmin"
+       name_prefix = (known after apply)
+       path        = "/"
+       policy      = jsonencode(
            {
+               Statement = [
+                   {
+                       Action   = [
+                           "iam:CreateAccessKey",
                        ]
+                       Effect   = "Allow"
+                       Resource = "arn:aws:iam::*:user/*"
                    },
+                   {
+                       Action    = [
+                           "iam:UpdateLoginProfile",
                        ]
+                       Condition = {
+                           StringEquals = {
+                               "iam:ResourceTag/Access Level" = [
+                                   "1",
+                                   "2",
                                ]
                            }
                        }
+                       Effect    = "Allow"
+                       Resource  = "arn:aws:iam::*:user/*"
                    },
                ]
+               Version   = "2012-10-17"
            }
        )
+       policy_id   = (known after apply)
+       tags_all    = (known after apply)
    }

  # module.iam_read_only_group.aws_iam_group_policy_attachment.group_policy_attachment["IAMUserChangePassword"] will be created
+   resource "aws_iam_group_policy_attachment" "group_policy_attachment" {
+       group      = "read-only-group"
+       id         = (known after apply)
+       policy_arn = "arn:aws:iam::aws:policy/IAMUserChangePassword"
    }

  # module.iam_read_only_group.aws_iam_group_policy_attachment.group_policy_attachment["ReadOnlyAccess"] will be created
+   resource "aws_iam_group_policy_attachment" "group_policy_attachment" {
+       group      = "read-only-group"
+       id         = (known after apply)
+       policy_arn = "arn:aws:iam::aws:policy/ReadOnlyAccess"
    }

  # module.iam_read_only_group.aws_iam_group_policy_attachment.group_policy_attachment["arn:aws:iam::aws:policy/IAMUserChangePassword"] will be destroyed
  # (because key ["arn:aws:iam::aws:policy/IAMUserChangePassword"] is not in for_each map)
-   resource "aws_iam_group_policy_attachment" "group_policy_attachment" {
-       group      = "read-only-group" -> null
-       id         = "read-only-group-20240214024410737500000001" -> null
-       policy_arn = "arn:aws:iam::aws:policy/IAMUserChangePassword" -> null
    }

  # module.iam_read_only_group.aws_iam_group_policy_attachment.group_policy_attachment["arn:aws:iam::aws:policy/ReadOnlyAccess"] will be destroyed
  # (because key ["arn:aws:iam::aws:policy/ReadOnlyAccess"] is not in for_each map)
-   resource "aws_iam_group_policy_attachment" "group_policy_attachment" {
-       group      = "read-only-group" -> null
-       id         = "read-only-group-20240214022809806800000006" -> null
-       policy_arn = "arn:aws:iam::aws:policy/ReadOnlyAccess" -> null
    }

  # module.iam_services_admin_group.aws_iam_group.group will be created
+   resource "aws_iam_group" "group" {
+       arn       = (known after apply)
+       id        = (known after apply)
+       name      = "iam-services-admin-group"
+       path      = "/"
+       unique_id = (known after apply)
    }

  # module.iam_services_admin_group.aws_iam_group_policy_attachment.group_policy_attachment["IAMServicesAdmin"] will be created
+   resource "aws_iam_group_policy_attachment" "group_policy_attachment" {
+       group      = "iam-services-admin-group"
+       id         = (known after apply)
+       policy_arn = (known after apply)
    }

  # module.iam_user_abbyz123.aws_iam_user.user will be updated in-place
!~  resource "aws_iam_user" "user" {
        id            = "abbyz123"
        name          = "abbyz123"
!~      tags          = {
+           "Access Level" = "1"
            "Project"      = "devops-security"
        }
!~      tags_all      = {
+           "Access Level" = "1"
#            (1 unchanged element hidden)
        }
#        (4 unchanged attributes hidden)
    }

  # module.iam_user_awlFCCamp.aws_iam_user.user will be updated in-place
!~  resource "aws_iam_user" "user" {
        id            = "awlFCCamp"
        name          = "awlFCCamp"
!~      tags          = {
+           "Access Level" = "1"
            "Project"      = "devops-security"
        }
!~      tags_all      = {
+           "Access Level" = "1"
#            (1 unchanged element hidden)
        }
#        (4 unchanged attributes hidden)
    }

  # module.iam_user_brittanyms.aws_iam_user.user will be updated in-place
!~  resource "aws_iam_user" "user" {
        id            = "brittanyms"
        name          = "brittanyms"
!~      tags          = {
+           "Access Level" = "1"
            "Project"      = "devops-security"
        }
!~      tags_all      = {
+           "Access Level" = "1"
#            (1 unchanged element hidden)
        }
#        (4 unchanged attributes hidden)
    }

  # module.iam_user_freaky4wrld.aws_iam_user.user will be updated in-place
!~  resource "aws_iam_user" "user" {
        id            = "freaky4wrld"
        name          = "freaky4wrld"
!~      tags          = {
+           "Access Level" = "1"
            "Project"      = "devops-security"
        }
!~      tags_all      = {
+           "Access Level" = "1"
#            (1 unchanged element hidden)
        }
#        (4 unchanged attributes hidden)
    }

  # module.iam_user_samuelusc.aws_iam_user.user will be updated in-place
!~  resource "aws_iam_user" "user" {
        id            = "samuelusc"
        name          = "samuelusc"
!~      tags          = {
+           "Access Level" = "1"
            "Project"      = "devops-security"
        }
!~      tags_all      = {
+           "Access Level" = "1"
#            (1 unchanged element hidden)
        }
#        (4 unchanged attributes hidden)
    }

  # module.iam_user_shikha0428.aws_iam_user.user will be updated in-place
!~  resource "aws_iam_user" "user" {
        id            = "shikha0428"
        name          = "shikha0428"
!~      tags          = {
+           "Access Level" = "1"
            "Project"      = "devops-security"
        }
!~      tags_all      = {
+           "Access Level" = "1"
#            (1 unchanged element hidden)
        }
#        (4 unchanged attributes hidden)
    }

  # module.iam_user_shinjonathan.aws_iam_user.user will be updated in-place
!~  resource "aws_iam_user" "user" {
        id            = "shinjonathan"
        name          = "shinjonathan"
!~      tags          = {
+           "Access Level" = "1"
            "Project"      = "devops-security"
        }
!~      tags_all      = {
+           "Access Level" = "1"
#            (1 unchanged element hidden)
        }
#        (4 unchanged attributes hidden)
    }

Plan: 5 to add, 7 to change, 2 to destroy.

❌ Error applying plan in Apply Terraform changes on merge #1

freaky4wrld
freaky4wrld previously approved these changes Feb 22, 2024
Copy link
Member

@freaky4wrld freaky4wrld left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks Good!!!

@chelseybeck chelseybeck merged commit 28d1065 into main Feb 22, 2024
1 check passed
Copy link

github-actions bot commented Feb 22, 2024

Terraform plan in terraform

Plan: 3 to add, 7 to change, 0 to destroy.
Terraform used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
+   create
!~  update in-place

Terraform will perform the following actions:

  # module.aws_custom_policies.aws_iam_policy.custom_policy["IAMServicesAdmin"] will be created
+   resource "aws_iam_policy" "custom_policy" {
+       arn         = (known after apply)
+       description = "Policy granting IAM services admins permissions to make changes to user accounts"
+       id          = (known after apply)
+       name        = "IAMServicesAdmin"
+       name_prefix = (known after apply)
+       path        = "/"
+       policy      = jsonencode(
            {
+               Statement = [
+                   {
+                       Action   = [
+                           "iam:CreateAccessKey",
                        ]
+                       Effect   = "Allow"
+                       Resource = "arn:aws:iam::*:user/*"
                    },
+                   {
+                       Action    = [
+                           "iam:UpdateLoginProfile",
                        ]
+                       Condition = {
+                           StringEquals = {
+                               "iam:ResourceTag/Access Level" = [
+                                   "1",
+                                   "2",
                                ]
                            }
                        }
+                       Effect    = "Allow"
+                       Resource  = "arn:aws:iam::*:user/*"
                    },
                ]
+               Version   = "2012-10-17"
            }
        )
+       policy_id   = (known after apply)
+       tags_all    = (known after apply)
    }

  # module.iam_read_only_group.aws_iam_group_policy_attachment.group_policy_attachment["ReadOnlyAccess"] will be created
+   resource "aws_iam_group_policy_attachment" "group_policy_attachment" {
+       group      = "read-only-group"
+       id         = (known after apply)
+       policy_arn = "arn:aws:iam::aws:policy/ReadOnlyAccess"
    }

  # module.iam_services_admin_group.aws_iam_group_policy_attachment.group_policy_attachment["IAMServicesAdmin"] will be created
+   resource "aws_iam_group_policy_attachment" "group_policy_attachment" {
+       group      = "iam-services-admin-group"
+       id         = (known after apply)
+       policy_arn = (known after apply)
    }

  # module.iam_user_abbyz123.aws_iam_user.user will be updated in-place
!~  resource "aws_iam_user" "user" {
        id            = "abbyz123"
        name          = "abbyz123"
!~      tags          = {
+           "Access Level" = "1"
            "Project"      = "devops-security"
        }
!~      tags_all      = {
+           "Access Level" = "1"
#            (1 unchanged element hidden)
        }
#        (4 unchanged attributes hidden)
    }

  # module.iam_user_awlFCCamp.aws_iam_user.user will be updated in-place
!~  resource "aws_iam_user" "user" {
        id            = "awlFCCamp"
        name          = "awlFCCamp"
!~      tags          = {
+           "Access Level" = "1"
            "Project"      = "devops-security"
        }
!~      tags_all      = {
+           "Access Level" = "1"
#            (1 unchanged element hidden)
        }
#        (4 unchanged attributes hidden)
    }

  # module.iam_user_brittanyms.aws_iam_user.user will be updated in-place
!~  resource "aws_iam_user" "user" {
        id            = "brittanyms"
        name          = "brittanyms"
!~      tags          = {
+           "Access Level" = "1"
            "Project"      = "devops-security"
        }
!~      tags_all      = {
+           "Access Level" = "1"
#            (1 unchanged element hidden)
        }
#        (4 unchanged attributes hidden)
    }

  # module.iam_user_freaky4wrld.aws_iam_user.user will be updated in-place
!~  resource "aws_iam_user" "user" {
        id            = "freaky4wrld"
        name          = "freaky4wrld"
!~      tags          = {
+           "Access Level" = "1"
            "Project"      = "devops-security"
        }
!~      tags_all      = {
+           "Access Level" = "1"
#            (1 unchanged element hidden)
        }
#        (4 unchanged attributes hidden)
    }

  # module.iam_user_samuelusc.aws_iam_user.user will be updated in-place
!~  resource "aws_iam_user" "user" {
        id            = "samuelusc"
        name          = "samuelusc"
!~      tags          = {
+           "Access Level" = "1"
            "Project"      = "devops-security"
        }
!~      tags_all      = {
+           "Access Level" = "1"
#            (1 unchanged element hidden)
        }
#        (4 unchanged attributes hidden)
    }

  # module.iam_user_shikha0428.aws_iam_user.user will be updated in-place
!~  resource "aws_iam_user" "user" {
        id            = "shikha0428"
        name          = "shikha0428"
!~      tags          = {
+           "Access Level" = "1"
            "Project"      = "devops-security"
        }
!~      tags_all      = {
+           "Access Level" = "1"
#            (1 unchanged element hidden)
        }
#        (4 unchanged attributes hidden)
    }

  # module.iam_user_shinjonathan.aws_iam_user.user will be updated in-place
!~  resource "aws_iam_user" "user" {
        id            = "shinjonathan"
        name          = "shinjonathan"
!~      tags          = {
+           "Access Level" = "1"
            "Project"      = "devops-security"
        }
!~      tags_all      = {
+           "Access Level" = "1"
#            (1 unchanged element hidden)
        }
#        (4 unchanged attributes hidden)
    }

Plan: 3 to add, 7 to change, 0 to destroy.

❌ Error applying plan in Apply Terraform changes on merge #1

Copy link

github-actions bot commented Feb 22, 2024

Terraform plan in terraform

Plan: 2 to add, 0 to change, 1 to destroy.
Terraform used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
+   create
-/+ destroy and then create replacement

Terraform will perform the following actions:

  # module.aws_custom_policies.aws_iam_policy.custom_policy["IAMServicesAdmin"] is tainted, so must be replaced
-/+ resource "aws_iam_policy" "custom_policy" {
!~      arn         = "arn:aws:iam::035866691871:policy/IAMServicesAdmin" -> (known after apply)
!~      id          = "*************************************************" -> (known after apply)
        name        = "IAMServicesAdmin"
+       name_prefix = (known after apply)
!~      policy_id   = "*********************" -> (known after apply)
-       tags        = {} -> null
!~      tags_all    = {} -> (known after apply)
#        (3 unchanged attributes hidden)
    }

  # module.iam_services_admin_group.aws_iam_group_policy_attachment.group_policy_attachment["IAMServicesAdmin"] will be created
+   resource "aws_iam_group_policy_attachment" "group_policy_attachment" {
+       group      = "iam-services-admin-group"
+       id         = (known after apply)
+       policy_arn = (known after apply)
    }

Plan: 2 to add, 0 to change, 1 to destroy.

❌ Error applying plan in Apply Terraform changes on merge #1

Copy link

github-actions bot commented Feb 22, 2024

Terraform plan in terraform

Plan: 2 to add, 0 to change, 1 to destroy.
Terraform used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
+   create
-/+ destroy and then create replacement

Terraform will perform the following actions:

  # module.aws_custom_policies.aws_iam_policy.custom_policy["IAMServicesAdmin"] is tainted, so must be replaced
-/+ resource "aws_iam_policy" "custom_policy" {
!~      arn         = "arn:aws:iam::035866691871:policy/IAMServicesAdmin" -> (known after apply)
!~      id          = "*************************************************" -> (known after apply)
        name        = "IAMServicesAdmin"
+       name_prefix = (known after apply)
!~      policy_id   = "*********************" -> (known after apply)
-       tags        = {} -> null
!~      tags_all    = {} -> (known after apply)
#        (3 unchanged attributes hidden)
    }

  # module.iam_services_admin_group.aws_iam_group_policy_attachment.group_policy_attachment["IAMServicesAdmin"] will be created
+   resource "aws_iam_group_policy_attachment" "group_policy_attachment" {
+       group      = "iam-services-admin-group"
+       id         = (known after apply)
+       policy_arn = (known after apply)
    }

Plan: 2 to add, 0 to change, 1 to destroy.

❌ Error applying plan in Apply Terraform changes on merge #1

Copy link

github-actions bot commented Feb 22, 2024

Terraform plan in terraform

Plan: 2 to add, 0 to change, 1 to destroy.
Terraform used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
+   create
-/+ destroy and then create replacement

Terraform will perform the following actions:

  # module.aws_custom_policies.aws_iam_policy.custom_policy["IAMServicesAdmin"] is tainted, so must be replaced
-/+ resource "aws_iam_policy" "custom_policy" {
!~      arn         = "arn:aws:iam::035866691871:policy/IAMServicesAdmin" -> (known after apply)
!~      id          = "*************************************************" -> (known after apply)
        name        = "IAMServicesAdmin"
+       name_prefix = (known after apply)
!~      policy_id   = "*********************" -> (known after apply)
-       tags        = {} -> null
!~      tags_all    = {} -> (known after apply)
#        (3 unchanged attributes hidden)
    }

  # module.iam_services_admin_group.aws_iam_group_policy_attachment.group_policy_attachment["IAMServicesAdmin"] will be created
+   resource "aws_iam_group_policy_attachment" "group_policy_attachment" {
+       group      = "iam-services-admin-group"
+       id         = (known after apply)
+       policy_arn = (known after apply)
    }

Plan: 2 to add, 0 to change, 1 to destroy.

✅ Plan applied in Apply Terraform changes on merge #1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants